<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>13_Fetch-文件上传的接口演练</title>
</head>
<body>
  
  <input class="file" type="file">
  <button class="upload">上传文件</button>

  <script>
    const uploadBtn = document.querySelector('.upload')
    uploadBtn.onclick = async function () {
      const file = document.querySelector('.file').files[0]
      const formData = new FormData()
      formData.append('avatar', file)

      const response = await fetch('http://localhost:3000/upload', {
        method: 'post',
        body: formData
      })

      const result = await response.json()
      console.log(result)
    }


  </script>

</body>
</html>